const gulp = require("gulp");
const {src,dest,watch,parallel,series} = gulp;
const minifyCSS = require("gulp-clean-css");
const autoprefixer = require("gulp-autoprefixer");
const htmlmin = require("gulp-htmlmin");
const sync = require("browser-sync");
const css_Minify = ()=>{
    return src("src/css/*.css",{"base": "src"})
    .pipe(autoprefixer())
    .pipe(minifyCSS())
    .pipe(dest("dist"));
};
const js_Module_Minify = ()=>{
    return src("src/js/*.js",{"base": "src"})
    .pipe(dest("dist"));
};
const HTML_Minify = ()=>{
    return src("src/index.html",{"base": "src"})
    .pipe(htmlmin({
        "collapseWhitespace": true, // 折叠HTML内空白字符
        "minifyCSS": true, // 折叠HTML嵌入CSS样式
        "minifyJS": true // 折叠Script标签内的嵌入JS
    }))
    .pipe(dest("dist"));
}
const liveServer = ()=>{
    watch('src/index.html',HTML_Minify);
// 被监视的文件对应任务
    sync.init({
        notify: false, // 禁用浏览器右上角的browerSync connected
        files: 'dist/**',// 监视DIST下的文件变化然后在浏览器上更新
        server: {
            baseDir: 'dist',
            // routes: {
            //     '/node_modules': 'node_modules'
            // }
        }
    });
}
module.exports = {
    HTML_Minify,
    js_Module_Minify,
    css_Minify,
    liveServer,
    build: parallel(HTML_Minify,css_Minify,js_Module_Minify),
    dev: series(parallel(HTML_Minify,css_Minify,js_Module_Minify),liveServer)
};